package com.ruoyi.common.utils.push;

import com.ruoyi.common.core.domain.PushBody;
import com.ruoyi.common.core.domain.entity.SysUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: ruohao
 * @Date: 2023/11/16
 **/

@Service
public class JiGuangPushServiceImpl implements JiGuangPushService {
    /** 一次推送最大数量 (极光限制1000) */
    private static final int max_size = 800;

    @Resource
    private MyJiGuangPushService jPushService;



    @Override
    public boolean pushAll(PushBody pushBody) {
        return jPushService.pushAll(pushBody);
    }

    @Override
    public boolean pushIos(PushBody pushBody) {
        return jPushService.pushIos(pushBody);
    }

    @Override
    public boolean pushIos(PushBody pushBody, List<String> registerIds) {
        registerIds = checkRegisterIds(registerIds); // 剔除无效registed
        return jPushService.pushIos(pushBody, registerIds);
    }

    @Override
    public boolean pushAndroid(PushBody pushBody) {
        return jPushService.pushAndroid(pushBody);
    }

    @Override
    public boolean pushAndroid(PushBody pushBody, List<String> registerIds) {
        registerIds = checkRegisterIds(registerIds); // 剔除无效registed
        return jPushService.pushIos(pushBody, registerIds);
    }

    @Override
    public List<String> checkRegisterIds(List<String> registerIds) {
        if (CollectionUtils.isEmpty(registerIds)) {
            return new ArrayList<>();
        }
        return registerIds.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
    }
}
